package com.example.zingalbumdownloader.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.zingalbumdownloader.item.ItemMyAlbum;
import com.example.zingalbumdownloader.model.Album;

public class MyAlbumAdapter extends ArrayAdapter<Album> {
	private Context myContext;
	private ArrayList<Album> arrayAlbum;

	public MyAlbumAdapter(Context context, int resourceid,
			ArrayList<Album> objects) {
		super(context, resourceid, objects);
		this.myContext = context;
		this.arrayAlbum = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View itemAlbum = convertView;
		if (itemAlbum == null) {
			itemAlbum = new ItemMyAlbum(myContext);
		}

		Album album = arrayAlbum.get(position);
		if (album != null) {
//			ImageView pic = ((ItemMyAlbum) itemAlbum).pic;
			TextView nameAlbum = ((ItemMyAlbum) itemAlbum).nameAlbum;
			// TextView namePerformer = ((ItemMyAlbum) itemAlbum).namePerformer;

			// pic.setImageBitmap(album.getBitmap());
			nameAlbum.setText(getFirstString(album.getTitle()));
			// namePerformer.setText(album.getPerformer());
		}

		return itemAlbum;
	}

	public String getFirstString(String string) {
		String[] subString = string.split("-");
		// Log.d("ZING", "name " + subString[0]);
		return subString[0];

	}
}
